﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Teamplate.Master" AutoEventWireup="true" CodeBehind="DauThauSach.aspx.cs" Inherits="WebNhaXuatBan.DauThauSach" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <a style="margin-left:30px;" href="default.aspx"><img src="Images/Folder-Home-Folder-icon.png" alt="Group EM09" /></a>
    <a style="margin-left:30px;"  href="DauThauSach.aspx"><img src="Images/auction-guyHover.png" alt="Group EM09" /></a>
    <a style="margin-left:30px;"  href="GianHangSach.aspx"><img src="Images/Books-2-icon.png" alt="Group EM09" /></a>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
 <div style="width:980px; margin-left:auto; margin-right:auto; border:1px solid #bad9eb;">
<div style="width:980px;height:30px; background-image:url(../Images/ThanhTieuDe.png);"></div>
<div id="timelabel"></div>
<div id="timelabel1"></div>
    <script type="text/javascript">
        var $j = jQuery.noConflict();
        function DongY(tam, show, thaydoi, maSach,soTien,landauthauthu,maTaiKhoan,tenTaiKhoan) {
            $j.ajax({
                type: "POST",
                url: "DauThauSach.aspx/DauGiaSach",
                data: "{'maSach':'" + maSach + "','soTien':'" + soTien + "','lanThau':'" + landauthauthu + "','maTaiKhoan':'" + maTaiKhoan + "','tenTaiKhoan':'" + tenTaiKhoan + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (message) {
                    if (message.d == "ok") {
                        window.location = "DauThauSach.aspx";
                    } else {
                        $j('#' + thaydoi).html(message.d);
                    }
                }
            });
        }
        function DauGia(tam,show) {
            $j('#' + tam).hide();
            $j('#' + show).show();
        }
        var bien = 0;
        setInterval(function () {
            bien = bien + 1;
        }, 1000);
    function CounterTimer(tam, leave) {
    if((leave-bien)>=0)
    {
        var day = Math.floor((leave-bien) / (60 * 60 * 24));
        var hour = Math.floor((leave - bien) / 3600) - (day * 24);
        var minute = Math.floor((leave - bien) / 60) - (day * 24 * 60) - (hour * 60);
        var second = Math.floor((leave - bien)) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
        hour = hour < 10 ? "0" + hour : hour;
        minute = minute < 10 ? "0" + minute : minute;
        second = second < 10 ? "0" + second : second;
        var remain = day + " Ngày " + hour + ":" + minute + ":" + second;
        document.getElementById(tam).innerHTML ="Thời Gian Còn Lại: <span style='color:red;'>"+ remain+"</span>";
        }
        else {
            document.getElementById(tam).innerHTML = "Thời Gian Còn Lại: <span style='color:red;'>Hết Hạn</span>";
        }
    }
    </script>
<div id="BODY">
<%
    BUS.ThauSachBUS sach = new BUS.ThauSachBUS();
    ArrayList dssach = sach.LayDanhSachThauSach();
   int soBatDau = 0;
   if (Request.QueryString["SoBatDau"] != null)
   {
       soBatDau = int.Parse(Request.QueryString["SoBatDau"]); 
   }
   int count = dssach.Count;
   int sotrang = 0;
   if (dssach.Count > 5)
   {
       count = 5;
       sotrang = dssach.Count / 5;
       if (dssach.Count % 5 > 0)
       {
           if (soBatDau == dssach.Count / 5)
           {
               count = dssach.Count % 5;
           }
           sotrang++;
       }
   }
   if (sotrang != 0 && sotrang != 1)
   { 
    %>
     <a style=" margin-left:2px; color:#4ba2d5" href="DauThauSach.aspx?SoBatDau=0" >Trang Đầu</a>
     <%int sob = soBatDau / 10;
                sob = sob * 10;
                int soc = sob + 10;
                if (soc > sotrang)
                {
                    soc = sotrang;
                }
                if (sob != 0)
                {
        %>
        <a style=" margin-left:2px; color:#4ba2d5;" href="DauThauSach.aspx?SoBatDau=<%=(sob - 1)%>"><< Trước</a>
        <%}
            for (int i = sob; i < soc; i++)
            {
                if (i == soBatDau)
                {
                    %><span><%=i %></span>
                    <%
                }
                else
                {%>
                    <a style=" margin-left:2px; color:#4ba2d5;" href="DauThauSach.aspx?SoBatDau=<%=i %>"><%=i %></a>
                        <%
                }
            }
            if (soc < sotrang)
            {
                %>
                <a style=" margin-left:2px; color:#4ba2d5;" href="DauThauSach.aspx?SoBatDau=<%=soc %>"><%=soc %></a><%
            }
            if (sotrang != 0 && sotrang != 1)
            {
                %>
                <a style=" margin-left:2px; color:#4ba2d5;" href="DauThauSach.aspx?SoBatDau=<%=sotrang-1 %>">Trang Cuối</a><%
            }
                     %>
        <%} %>
        <br /><span style="margin-left:2px; margin-top:5px;">Hiển Thị:<%=" "+count %>/<%=dssach.Count+" kết quả" %></span>
    <%
   for (int j = soBatDau*5; j < soBatDau*5+count; j++)
   {%>
   <br />
   <hr />
   <div style="height:300px;margin-top:5px;margin-left:5px;width:100%;">
   <div style="height:300px;float:left;width:300px;">
   <a href="#"><img src="<%=((DTO.ThauSachDTO)dssach[j]).NgayThangNamBatDau %>" alt="<%=((DTO.ThauSachDTO)dssach[j]).NgayThangNamBatDau %>") /></a>
   </div>
   <div style="height:300px;float:left;width:600px;">
   <span style="color:#366276; font-size:35px;"><%= ((DTO.ThauSachDTO)dssach[j]).TenThauSach%></span>
   <br />
   <br />
   <span style="font-size:20px;">Số Tiền Bắt Đầu:<%=" "%></span><span style="color:red;font-size:20px;"><%=" " + ((DTO.ThauSachDTO)dssach[j]).SoTienCTYRaThau%>$</span>
   <div id="thayDoi<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>" >
   <span style="font-size:20px;">Số Tiền Ra Giá Sau Cùng:<%=" "%></span><span style="color:red;font-size:20px;"><%=" " + ((DTO.ThauSachDTO)dssach[j]).SoTienCuaNhaCungCapTraThau%>$</span>
   <br />
   <span style="font-size:20px;">Số Người Đã Tham Gia:<%=" "%></span><span style="color:red;font-size:20px;"><%=" " + ((DTO.ThauSachDTO)dssach[j]).LanDauThauThu%></span>
   <br />
   <% DTO.TaiKhoanDTO tk = new DTO.TaiKhoanDTO();
      tk.MaTaiKhoan = ((DTO.ThauSachDTO)dssach[j]).MaTaiKhoan;
      BUS.TaiKhoanBUS tkbus = new BUS.TaiKhoanBUS();
      tk=tkbus.LayTaiKhoanTheoMaTaiKhoan(tk);
        %>
   <span style="font-size:20px;">Tài Khoản Đấu Giá Sau Cùng:<%=" "%></span><span style="color:blue;font-size:20px;"><%=" "+tk.TenTaiKhoan%></span>
   </div>
   <span style="font-size:20px;">Thời Gian Kết Thúc:<%=" "%></span><span style="color:red;font-size:20px;"><%=ChuyenNgay(((DTO.ThauSachDTO)dssach[j]).ThoiGianBatDau).Day + "/" + ChuyenNgay(((DTO.ThauSachDTO)dssach[j]).ThoiGianBatDau).Month + "/" + ChuyenNgay(((DTO.ThauSachDTO)dssach[j]).ThoiGianBatDau).Year + "  " + ChuyenNgay(((DTO.ThauSachDTO)dssach[j]).ThoiGianBatDau).ToShortTimeString()%></span>
   <%if (((DTO.ThauSachDTO)dssach[j]).DaXoa==false)
     { %>
   <div id="thoigian<%=j %>" style="font-size:20px;"></div>
   <script type="text/javascript">
    setInterval(CounterTimer, 1000, 'thoigian<%=j %>',<%=GetEndTime(((DTO.ThauSachDTO)dssach[j]).ThoiGianBatDau ) %>);
    </script>
    <%} %>
   <br />
   <%if (Session["TaiKhoan"] != null)
     { %>
   <a id="buttonDauGia<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>" onclick="DauGia('buttonDauGia<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>','themSach<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>');" href="#DauGia<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>"><img src="Images/daugia.png" /></a>
   <div id="themSach<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>">
       <asp:Label ID="Label1" runat="server" Text="Số Tiền Bạn Ra Giá " 
           Font-Bold="True" Font-Size="Larger" ForeColor="#893434"></asp:Label><input id="text<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>"
               type="text" />
               
    <a id="A" onclick="DongY('themSach<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>', 'buttonDauGia<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>', 'thaydoi<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>', '<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>', $j('#text<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>').val(), '<%=((DTO.ThauSachDTO)dssach[j]).LanDauThauThu%>', '<%=((DTO.TaiKhoanDTO)Session["TaiKhoan"]).MaTaiKhoan %>', '<%=((DTO.TaiKhoanDTO)Session["TaiKhoan"]).TenTaiKhoan %>');"  href="#DauGia<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>"><img src="Images/dongy.png" /></a>
    <br />
    Chú Ý: Tiền Đấu Giá Phải Lớn Hơn Tiền Đấu Giá Sau Cùng 1$.
    <br />
    <span id="thaydoi<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>" style="color:red;"></span>
   </div>
   <script type="text/javascript">
       $j('#themSach<%=((DTO.ThauSachDTO)dssach[j]).MaThauSach %>').hide();
    </script>
    <%}
     else
     { %>
     <a href="DangKy.aspx"><img src="Images/daugia.png" /></a>
     <%} %>
   </div>
   </div>
   <%} %>
   <div style="width:980px;height:10px;"></div>
</div>
</div>
</asp:Content>
